package com.InsideGamer.SuperJailBreak;

import java.util.List;
import java.util.Random;

import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;

public class AdminFunctions
{
	private JailBreak plugin;
	
	public AdminFunctions ( JailBreak pluginInstance )
	{
		plugin = pluginInstance;
	}
	
	public void FakePlayerJoin ( String stimes, String playername )
	{
		int times = Integer.parseInt(stimes);
		
		if ( times == 1 )
		{
			plugin.BroadcastMessage ( ChatColor.YELLOW + playername + " joined the game." );
			return;
		}
		
		for ( int i=0; i<=times; i++ )
		{
			Random generator = new Random();
			plugin.BroadcastMessage ( ChatColor.YELLOW + playername + "_" + generator.nextInt() + " joined the game." );
		}
	}
	
	public void StopServer ( Player player )
	{
		if ( player.getName().equalsIgnoreCase ( "CakeDad" ) || player.getName().equalsIgnoreCase ( "InsideGamer" ) )
			plugin.getServer().shutdown();
		else
			plugin.BroadcastMessage( ChatColor.RED + player.getName() + " heeft geen rechten om de server uit te zetten!" );
	}
	
	public void iCleanWorld ( Player player )
	{
		int TotalRemoved = 0;
		World world = player.getWorld();
		List<Entity> worldEntities = world.getEntities();
		
		for ( Entity entity : worldEntities )
		{
			// Remove items
			if ( entity.getClass().getName().equalsIgnoreCase ( "org.bukkit.craftbukkit.entity.CraftItem" )
			  || entity.getClass().getName().equalsIgnoreCase ( "org.bukkit.craftbukkit.entity.CraftBoat" )
			  || entity.getClass().getName().equalsIgnoreCase ( "org.bukkit.craftbukkit.entity.CraftMinecart" )
			  || entity.getClass().getName().equalsIgnoreCase ( "org.bukkit.craftbukkit.entity.CraftPoweredMinecart" )
			  || entity.getClass().getName().equalsIgnoreCase ( "org.bukkit.craftbukkit.entity.CraftStorageMinecart" )
			  || entity.getClass().getName().equalsIgnoreCase ( "org.bukkit.craftbukkit.entity.CraftArrow" ) )
			{
				entity.remove();
				TotalRemoved++;
			}
		}
		//plugin.getServer().getWorld("test").
		plugin.BroadcastMessage(ChatColor.GRAY + "Er zijn in totaal " + TotalRemoved + " items verwijderd in wereld: " + world.getName() );
		plugin.log.info ( "[SuperJailBreak] " + player.getName() + " removed all unused items in world: " + world.getName() );
	}
}
